/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Ex6.Banking;

/**
 *
 * @author Root
 */
public class Main {

    private Customer[] customer = new Customer[5];
    private int numberOfCustomer;

    public static void main(String[] args) {
        Main b = new Main();
        double interest, balance, protect;
        Customer c;
        Account a;
        String[] fnames = {"John", "Simms", "Bryant", "Soley", "Soley"};
        String[] lnames = {"Smith", "Jane", "Owen", "Tim", "Maria"};
        //jane smith
        System.out.println("Creating the customer Jane smith ");
        b.addCustomer("Jane", "Smith");
        balance = 500;
        interest = 3;
        System.out.println("Creating her Saving Account with a " + balance + " balance and " + interest + " % interest .");
        c = b.getCustomer(0);
        a = new SavingsAccount(balance, interest);
        c.setAccount(a);

        //owen bryant

        System.out.println("Creating the customer Owen Bryant ");
        b.addCustomer("Owen", "Bryant");
        balance = 500;
//        interest = 3;
        System.out.println("Creating her Saving Account with a " + balance + " balance and no overdraft protection .");
        c = b.getCustomer(1);
        a = new CheckingAccount(500);
        c.setAccount(a);

        //tim soley

        System.out.println("Creating the customer Tim Soley ");
        b.addCustomer("Tim ", "Soley");
        balance = 500;
        protect = 500;
//        System.out.println("Creating her Saving Account with a " + balance + " balance and " + interest + " % interest .");
        c = b.getCustomer(2);
        a = new CheckingAccount(balance, protect);
        c.setAccount(a);

        //maria soley

        System.out.println("Creating the customer Maria Soley ");
        b.addCustomer("Maria", "Soley");
        balance = 500;
        interest = 3;
        System.out.println("Maria shares her Checking Account with her husband Tim ");
        c = b.getCustomer(3);
//        a = new SavingsAccount(balance, interest);
        c.setAccount(a);

        c = b.getCustomer(0);
        transact(c, 150, 22.5, 47.62, 400);
        c = b.getCustomer(1);
        transact(c, 150, 22.5, 47.62, 400);
        c = b.getCustomer(2);
        transact(c, 150, 22.5, 47.62, 400);
        c = b.getCustomer(3);
        transact(c, 0, 150, 750, 0);




    }

    private static void transact(Customer c, double w1, double dep, double w2, double w3) {
        CheckingAccount ch;
        Account a = c.getAccount();
        boolean success = true;
        CheckingAccount u = (CheckingAccount) a;
        System.out.println("Current overdraft protection is " + u.getOverdrafProtecttion());
        //withdraw
        if (w1 > 0) {
            success = a.withdraw(w1);
            System.out.println("Withdraw " + w1 + " : " + success);
        }
        //deposit
        success = a.Deposit(dep);
        System.out.println("Deposit " + dep + " : " + success);
        //withdraw
        if (w2 > 0) {
            success = a.withdraw(w2);
            System.out.println("Withdraw " + w2 + " : " + success);
        }
        //withdraw
        if (w3 > 0) {
            success = a.withdraw(w3);
            System.out.println("Withdraw " + w3 + " : " + success);
        }
        System.out.println("customer [ " + c.getFirstName() + " , " + c.getLastName() + " ] has a balance of " + a.balance);
    }

    public void addCustomer(String f, String l) {
        Customer cu = new Customer(f, l);

        customer[numberOfCustomer] = cu;
        numberOfCustomer++;


    }

    public int getNumberOfCustomer() {
        return customer.length;
    }

    public Customer getCustomer(int index) {
//        Customer c = new Customer();
//        c.getFirstName();
//        c.getLastName();
//        c.getAccount();
        return customer[index];
    }

    public Main() {
    }
}
